package com.mach.platform.sprider.dev;

import com.mach.platform.sprider.Conf;
import com.mach.platform.util.SqlHelper;

/*
    取得变频器数据抓取器,一个对象针对一个采集模块
 */
public class TransducerSNDDev extends GerenalStatusDev  {


    protected SqlHelper sqls;

    public TransducerSNDDev(String ip, Integer port, Integer devID, String devName) {
        super(ip,port,devID,devName);

        this.sqls  = Conf.getSqlHelper();

    }



    public static void main(String[] args){
        TransducerSNDDev td = new TransducerSNDDev("192.168.3.91",8000,5,"8#变频器（PA2工艺16H）");
        Integer status = td.getStatus();
        System.out.println("status="+status);
    }


    @Override
    public Integer getStatus() {
        Integer result = 3;
        Integer cv=0x0CA8;
        try {
            byte[] repData = this.getDataRtu(0x0CA8,1);
            if(repData.length <1)return null;
            byte[] data = ByteUtil.subData(repData,3,2);
            data = ByteUtil.reverse(data);
//            result = ByteUtil.getFloat(data);
            Integer code = ByteUtil.getShort(data) * 1;

            if(code == 8 || code == 23){
                result = 2;
            }else{
                result = 1;
            }

            //TODO testBeep
            //result = 2;//test


            System.out.println("int=" + result );
        } catch (Exception e) {
            System.out.println("excep devId:" + this.devName + " " + e.getMessage());
        }


        return result;
    }
}
